//
//  PersonViewModel.swift
//  MiaoTan
//
//  Created by 于航 on 2024/9/22.
//

import SwiftUI
import PhotosUI

class PersonViewModel: ObservableObject {
    @Published var selectedImage : UIImage? = nil
    @Published var imageSlection: PhotosPickerItem? = nil {
        didSet {
            setImage(from: imageSlection)
        }
    }
    
    func setImage(from imageSelection: PhotosPickerItem?) {
        guard let imageSelection else {return}
        
        Task {
            if let data = try? await imageSelection.loadTransferable(type: Data.self) {
                if let uiImage = UIImage(data: data) {
                    selectedImage = uiImage
                    return
                }
            }
        }
    }
    
}
